RBScript Class
Used to execute REALbasic code within a running (compiled) application.
More information available in parent classes: Object
Notes
The RBScript language is an implementation of the REALbasic language that allows end users to write and execute REALbasic code within a compiled application. Scripts are compiled into machine language, rather then being interpreted.
Since RBScript is a class, you use it by creating an instance of this class either via code or by adding an RBScript control to a window. The easiest way to use RBScript is to assign the code to the Source property of the RBScript object and call the Run method.
To provide information to an RBScript while it's running, use the Input function. This function calls the Input event of the RBScript object where you can return the information you wish returned by the Input function in your RBScript code. In the following example, the results of the Input function are assigned to a variable:
The Input function takes a String that can be used to provide a prompt in case you are going to provide a dialog box in which the user enters the information. Since the Input function returns a String and we want to store the value as an integer, the Val function is used to convert the string to an integer. In this case, if the number of years is going to be entered into an EditField called Editfield1, then the Input event of the RBScript object would look like this:
When the Run method of the RBScript object is called, the code will be compiled and then executed. Since the Input function is called, the Input event of the RBScript object is executed and the contents of the Text property of the EditField is returned and assigned to the Years variable. Then the Days value is calculated.
Getting Information From RBScript
You obtain data from the RBScript using the Print method. This method takes a String and passes it to the Print event of the RBScript object. Here is the example modified to use the Print function:
You access the value passed to the Print method through the Print event. For example, if you want to assign the value to the Text property of a StaticText object, the code for the Print event of the RBScript object would look like this:
Handling Errors in Your Code
If an error occurs while RBScript is compiling your code, the CompilerError event of the RBScript object will be called and will be passed appropriate error information so you can then decide how to handle the error. If the error occurs while the code is running, the RuntimeError event of the RBScript object is called and is passed appropriate error information. You can then decide how to respond to the error.
Variables and Constants
All numeric and alphanumeric operators are supported:
+, -, *, /, \, Mod, <, =, >, <=, >=, <>.
Logical operators: And, Not, Or.
All forms of comments are supported: ', //, and REM.
Data Types
RBScript supports the following data types:
Arrays can use any of these types.
Control Structures
All the control structures specified in this Language Reference are supported. This includes:
Function...
Sub...
For... Next
Do... Loop
If... Then... End If
Select Case... End Select
While...Wend
Return statement
Classes
You can create a class using the Class...End Class structure. A new class can have properties, methods, and events.
Dim i as Integer //Property definitions..
Dim c as Color
Sub myMethod (x as Integer, y as Integer)
//Method definition goes here
End Sub
//Class definition
End Class
A class can be subclassed from another class using the "Inherits" declaration.
Modules
You can create modules using the Module structure. For example:
Modules are similar to REALbasic modules. The differences are that properties are always protected and constants are not allowed. You can get the effect of a public property or constant by simply putting the Dim or Const statement outside of the module.
TypeCasting
Typecasting is supported. Use the desired type's name as a function whose only argument is the object reference you want to cast. If it fails, it will trigger an IllegalCastException error.
"Super" keyword
The new "Super" keyword lets you call overridden methods without having to specify which class the method came from. This works for constructors as well. You can call overridden superclass methods using REALbasic's classname.methodname() syntax.
Inheritance
Class inheritance is implemented with the "Inherits" declaration.
Inherits NewClass
//continue coding here....
End Class
Events
Classes can declare new events using a New Event declaration.
Methods can handle such events using the Handles Event declaration. For example:
New Event myEvent (myParameter as DataType) as DataType
End Class
Class mySubClass
Inherits myClass
Function myEvent (myParameter as DataType) Handles Event
//continue with function here
End Function
End Class
Interfaces
RBScript now supports interfaces, declared by the Interface...End Interface structure. Interface methods are declared with a Sub or Function line just as they would be declared inside a class, but they have no contents and need no End Sub or End Function line:
Sub Move( x As Integer, y As Integer)
Function LocationX() As Integer
Function LocationY() As Integer
End Interface
Function declarations with no parameters must have empty parentheses, as shown above.
A class may declare that it implements an interface with the Implements keyword:
Implements MovableItem
End Class
Classes can implement any number of interfaces, but they must provide all of the methods listed in the interface. Interfaces can be used in all the situations as in REALbasic.
Input and Output
Function | Comments |
Input(Prompt as String) | Retrieves input from the user. This function triggers the Input event. |
Print(String) | Sends output to the implied output device. This function triggers the Print event. |
Functions
Standard library functions are supported as follows. These functions work as specified in this Language Reference unless comments indicate otherwise. String functions can be called using the syntax of methods, just as in REALbasic.
Compiler error numbers returned in errorNumber are shown below:
Error Number | Description |
1 | Syntax does not make sense. |
2 | Type mismatch. |
3 | Select Case does not support that type of expression. |
4 | The compiler is not implemented (obsolete). |
5 | The parser's internal stack has overflowed. |
6 | Too many parameters for this function. |
7 | Not enough parameters for this function call. |
8 | Wrong number of parameters for this function call. |
9 | Parameters are incompatible with this function. |
10 | Assignment of an incompatible data type. |
11 | Undefined identifier. |
12 | Undefined operator. |
13 | Logic operations require Boolean operands. |
14 | Array bounds must be integers. |
15 | Can't call a non-function. |
16 | Can't get an element from something that isn't an array. |
17 | Not enough subscripts for this array's dimensions. |
18 | Too many subscripts for this array's dimensions. |
19 | Can't assign an entire array. |
20 | Can't use an entire array in an expression. |
21 | Can't pass an expression as a ByRef parameter. |
22 | Duplicate identifier. |
23 | The backend code generator failed. |
24 | Ambiguous call to overloaded method. |
25 | Multiple inheritance is not allowed. |
26 | Cannot create an instance of an interface. |
27 | Cannot implement a class as though it were an interface. |
28 | Cannot inherit from something that is not a class. |
29 | This class does not fully implement the specified interface. |
30 | Event handlers cannot live outside of a class. |
31 | It is not legal to ignore the result of a function call. |
32 | Can't use "Self" keyword outside of a class. |
33 | Can't use "Me" keyword outside of a class. |
34 | Can't return a value from a Sub. |
35 | An exception object required here. |
36-39 | Obsolete. |
40 | Destructors can't have parameters. |
41 | Can't use "Super" keyword outside of a class. |
42 | Can't use "Super" keyword in a class that has no parent. |